/*
 * it creates the other controllers,
 * and in many ways then turns control over to these other controllers.
 * 
 * it does the database connection stuff it needs to do,
 * constructs the main frame (JFrame) of the application,
 */
package Main;

import Controller.*;
import View.*;
import Model.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainController {
	private OrderController orderController;
	private LoginController loginController;
        
        public MainView mainView;
	
        /* Constructor
	 * I'm constructing each controller.
	 * I'm giving each controller a reference back to the MainController.
	 * This is useful for making various callback.
	 */
	public MainController() {
            loginController = new LoginController(this);
            orderController = new OrderController(this);
               
                
                mainView = new MainView();
                this.mainView.addMainLoginButtonListener(new MainLoginButtonListener());
                this.mainView.addMainLogoutButtonListener(new MainLogoutButtonListener());
                //Order
                this.mainView.addMainOrderButtonListener(new MainOrderButtonListener());
                
	}
        
        public class MainLoginButtonListener implements ActionListener{
            public void actionPerformed(ActionEvent e) {
                loginController.getLoginView().setVisible(true);
            }
        }
        
        public class MainLogoutButtonListener implements ActionListener{
            public void actionPerformed(ActionEvent e) {
                mainView.mainLogoL.setText("Welcome                    ");
                mainView.mainLogoutB.setVisible(false);
                mainView.mainLoginB.setVisible(true);
                mainView.mainOrderB.setEnabled(false);;
                mainView.mainAdminB.setEnabled(false);
                mainView.mainSmpsB.setEnabled(false);                
            }
        }
        
        public class MainOrderButtonListener implements ActionListener{
            public void actionPerformed(ActionEvent e) {
                orderController.getOrderView().setVisible(true);
            }
        }
         
        public OrderController getOrderController() {
            return orderController;
        }

        public LoginController getLoginController() {
            return loginController;
        }
        
        
        
	public static void main(String[] args) {
           //Schedule a job for the event-dispatching thread:
           //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                  MainController MC = new MainController();
                }
            });

	}

}
